//
//  CommandButtonView.m
//  SlashEM
//
//  Created by dirk on 1/2/10.
//  Copyright 2010 Dirk Zimmermann. All rights reserved.
//

//  This file is part of Slash'EM.
//
//  Slash'EM is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, version 2 of the License only.
//
//  Slash'EM is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Slash'EM.  If not, see <http://www.gnu.org/licenses/>.

#import "CommandButtonView.h"
#import "UIFactory.h"

@implementation CommandButtonView

+ (float)requiredHeight {
	UIControl *sizeTestButton = [UIFactory buttonWithTitle:@"Test Title"];
	[sizeTestButton sizeToFit];
	return sizeTestButton.frame.size.height;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}

- (void)layoutSubviews {
	float totalSubViewWidth = 0.0f;
	for (UIView *view in self.subviews) {
		totalSubViewWidth += view.bounds.size.width;
	}
	CGRect bounds = self.bounds;
	bounds.size.width = totalSubViewWidth;
	self.bounds = bounds;
	float currentX = 0;
	for (UIView *view in self.subviews) {
		CGRect frame = view.frame;
		frame.origin.x = currentX;
		currentX += frame.size.width;
		view.frame = frame;
	}
}

- (void) addSubview:(UIView *)view {
	[view sizeToFit];
	[super addSubview:view];
}

- (void)dealloc {
    [super dealloc];
}

@end
